package co.com.services.maestro;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.MaestroDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartMaestroService")
public class MaestroService {
	@GET
	@Path("/getAllMaestro")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getMaestro() throws NamingException{
		return Response.ok(DelegateContextEJB.getMaestroBeanLocal().consultarAllMaestro())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getMaestroId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getMaestroId(MaestroDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getMaestroBeanLocal().consultarMaestroId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setMaestro")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setMaestro( MaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getMaestroBeanLocal().insertarMaestro(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editMaestro")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditMaestro(MaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getMaestroBeanLocal().editMaestro(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeMaestro")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveMaestro(MaestroDTO json){ 
		return Response.ok(DelegateContextEJB.getMaestroBeanLocal().removeMaestro(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
}